home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1997
/
MacHack 1997.toast
/
Hacks
/
Hacks ’93
/
PageTool 1.0
/
Page.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-17
|
7KB
|
265 lines
/*
File: Page.c
Contains: main page tool contents
Written by: Brian Topping
Copyright: © 1993 by Brian Topping, all rights reserved.
Change History (most recent first):
6/17/93 BET added optional zone string plus server instead of
just zone with assumed server name. This hasn't
been tested because I don't have PagerPro at MacHack,
but it isn't rocket science either!
To Do:
*/
#include <Types.h>
#include <ctype.h>
#include <string.h>
#include <Strings.h>
#include <stdio.h>
#include <CursorCtl.h>
#include <Errors.h>
#include <AppleEvents.h>
#include <GestaltEqu.h>
#include <Script.h>
#include <PLStringFuncs.h>
#include <PPCToolBox.h>
#include <Fonts.h>
#include "PagerPROAECalls.h"
#include "AutoGuest.h"
AEAddressDesc targetAddress; /* target address */
long userRefNum; /* user ref num */
char *toolName;
showError(OSErr theError)
{
printf("### %s - an error occurred: %d\n",toolName,theError);
}
initPPSData ()
{
/* AppleEvent data */
targetAddress.dataHandle = nil;
userRefNum = 0;
}
/*----------------------------------------------------------------------
This function shows the recommended way that your application
should use the authentication patches
Since these routines patch traps which change the behavior of
the OS, it is a good idea to avoid installing them whenever
possible. Ideally, your application will only call the
function 'InitialAESend' when it knows that it must start a
new session (i.e., it has a new address that it has never
messaged to before); at other times, it should call AESend
directly.
----------------------------------------------------------------------*/
OSErr InitialAESend( AppleEvent* question, AppleEvent* reply, AESendMode sendMode, AESendPriority sendPriority, long timeOutTicks, IdleProcPtr idleProc, EventFilterProcPtr filterProc )
{
long oldPPC;
long oldNoInteraction;
Boolean useNoInteractionPatch;
OSErr theErr;
/*
// Install the two AutoGuest patches. Only put in
// the 'noInteractionPatch' if we really need it
*/
useNoInteractionPatch = !InForeGround();
oldPPC = InstallPPCAutoGuest();
if( useNoInteractionPatch )
oldNoInteraction = InstallNoInteractionPatch();
/*
// Now that we have installed the patch or patches,
// try the AESend
*/
theErr = AESend( question, reply, sendMode, sendPriority, timeOutTicks, idleProc, filterProc );
/*
// Deinstall any patch that we installed
*/
if( useNoInteractionPatch )
DeinstallNoInteractionPatch(oldNoInteraction);
DeinstallPPCAutoGuest(oldPPC);
return theErr;
}
OSErr doesAddressExistInitial ( addString, retValue, targetAddress, errString)
StringPtr addString; /* User or group name */
long *retValue; /* Returned value */
AEAddressDesc *targetAddress; /* Target application address */
StringPtr errString; /* Returned error string */
{
AppleEvent theAppleEvent;
AppleEvent reply;
AEDescList param1List;
AEDesc param1;
Size actualSize;
DescType returnedType;
OSErr retError;
errString [0] = 0;
reply.dataHandle = nil;
/* create a CoreEvent, DoObjectsExist */
retError = AECreateAppleEvent ( kCoreEventClass, kAEDoObjectsExist, targetAddress, kAutoGenerateReturnID, kAnyTransactionID, &theAppleEvent);
if ( retError == noErr )
{
/* param1: address name */
retError = AECreateList ( nil, 0, false, ¶m1List);
retError = AECreateDesc ( typeChar, (Ptr) &addString [1], addString [0], ¶m1);
retError = AEPutDesc ( ¶m1List, 0, ¶m1);
retError = AEPutParamDesc ( &theAppleEvent, keyDirectObject, ¶m1List);
/* send the event */
retError = AESend ( &theAppleEvent, &reply, kAEWaitReply + kAENeverInteract, kAENormalPriority, 120, nil, nil);
if ( retError == noErr )
{
/* get the size */
if ( AEGetParamPtr ( &reply, keyAEResult, typeLongInteger, &returnedType, (Ptr) retValue, sizeof(long), &actualSize) != noErr )
{
/* get the error message */
AEGetParamPtr ( &reply, keyErrorString, typeChar, &returnedType, (Ptr) errString, 255, &actualSize);
errString [actualSize] = nil;
c2pstr ( (Ptr) errString);
retError = errAEEventFailed;
}
}
if ( param1.dataHandle )
AEDisposeDesc ( ¶m1);
if ( reply.dataHandle )
AEDisposeDesc ( &reply);
}
return ( retError);
}
OSErr initPagerPROAEInterfaceNoDialog (AEAddressDesc *targetAddress, LocationNameRec *theLocation, PortInfoRec *thePortInfo)
{
OSErr retError;
unsigned long defUserRefNum;
Str32 userName;
IPCListPortsPBRec ipcPB;
PortInfoRec localPortInfo;
TargetID targetID;
/* select a PagerPRO to link to */
ipcPB.startIndex = 0;
ipcPB.requestCount = 1;
ipcPB.portName = &(thePortInfo->name);
ipcPB.locationName = theLocation;
ipcPB.bufferPtr = &localPortInfo;
if ((retError = IPCListPorts(&ipcPB,false)) == noErr)
{
if (ipcPB.actualCount != 1)
return(69);
/* prepare target address */
BlockMove ( &localPortInfo.name, &targetID.name, sizeof(PPCPortRec));
BlockMove ( theLocation, &targetID.location, sizeof(LocationNameRec));
retError = AECreateDesc ( typeTargetID, (Ptr) &targetID, sizeof(TargetID), targetAddress);
userName [0] = 0;
defUserRefNum = 0;
}
return ( retError);
}
getPPCData (char *zoneStr, char *serverStr)
{
OSErr retError;
LocationNameRec theLocation;
PortInfoRec thePortInfo;
long aeAttribute;
/* see if ppc need initialization */
retError = Gestalt ( gestaltAppleEventsAttr, &aeAttribute);
if ( retError == noErr )
{
if ( (aeAttribute & gestaltAppleEventsPresent) == 0 )
{
/* select a PagerPRO to link to */
thePortInfo.name.nameScript = smRoman;
PLstrcpy(thePortInfo.name.name, "\pPagerPRO Server");
thePortInfo.name.portKindSelector = ppcByString;
PLstrcpy(thePortInfo.name.u.portTypeStr,"\p=");
theLocation.locationKindSelector = ppcNBPLocation;
PLstrcpy(theLocation.u.nbpEntity.objStr,serverStr);
PLstrcpy(theLocation.u.nbpEntity.typeStr, "\pPPCToolBox");
PLstrcpy(theLocation.u.nbpEntity.zoneStr, zoneStr);
retError = initPagerPROAEInterfaceNoDialog (&targetAddress,&theLocation,&thePortInfo);
}
}
return (retError);
}
main(int argc, char *argv[])
{
char user[64],message[64],zone[64],server[64],errString[256];
long retValue;
OSErr theError;
toolName = argv[0];
printf("PageTool by Brian Topping\n",toolName);
if (argc != 4) {
printf("### %s -- Error in parameters\n",toolName);
printf("### %s -- Usage \"%s <[serverZone:]serverName> <user> <message>\"\n",toolName,toolName);
return 1;
}
if (sscanf("%s:%s",zone,server) != 2)
strncpy(zone,argv[1],64);
else
c2pstr(server);
c2pstr(zone);
strncpy(user,argv[2],64);
c2pstr(user);
strncpy(message,argv[3],64);
c2pstr(message);
InitGraf ( &qd.thePort);
SetFScaleDisable(true);
initPPSData ();
if ( (theError = getPPCData(zone,server)) != noErr ) {
showError(theError);
return 2;
}
doesAddressExistInitial ( (StringPtr) "\pany address", &retValue, &targetAddress, errString);
if (theError = doAddressExist ( user, &retValue, &targetAddress, errString)){
showError(theError);
return 2;
}
if (theError = sendMessage ( NORMALPRIORITY, user, message, &targetAddress, errString)){
showError(theError);
return 2;
}
}